package com.clr.springboot.config;

import com.clr.springboot.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 车礼荣
 * @version 1.0
 * Create by 2025/3/20 10:15
 */

//扩展SpringMvc
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //扩展视图控制器 映射器
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //浏览器发送/welcome请求 到达welcome页面
        registry.addViewController("/welcome").setViewName("index");
        registry.addViewController("/main").setViewName("main");
        registry.addViewController("/Login").setViewName("login");
        registry.addViewController("/toAddUser").setViewName("add");
        registry.addViewController("/tosuccess").setViewName("success");
        registry.addViewController("/ToRegister").setViewName("register");

    }


    //拦截器-登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*")
                .excludePathPatterns("/Login","/dologin","/index","/login","/ToRegister","/register","/captcha");
    }
}
